﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;

namespace EditorialAdministration
{
    public partial class ActiveRowControl : UserControl
    {
        public ActiveRowControl()
        {
            if (ActiveIndex == null)
            {
                ActiveIndex = this;
                //this.lnkRow.Style = (Style)Resources["FocusedItemStyle"];
            }
            // Required to initialize variables
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(ActiveRowControl_Loaded);
        }

        void ActiveRowControl_Loaded(object sender, RoutedEventArgs e)
        {
            ActiveIndex.lnkRow.Style = (Style)Resources["FocusedItemStyle"];
        }

        public static readonly DependencyProperty AppNameProperty = DependencyProperty.Register("AppName", typeof(string), typeof(ActiveRowControl), new PropertyMetadata(AppNameChanged));

        public static void AppNameChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            ActiveRowControl control = (ActiveRowControl)sender;
            control.lblName.Content = (string)e.NewValue;

        }

        //public static readonly DependencyProperty AppNameProperty = DependencyProperty.Register("AppName", typeof(string), typeof(ActiveRowControl), new PropertyMetadata(AppNameChanged));
        private static ActiveRowControl ActiveIndex
        {
            get;
            set;
        }

        public string AppName
        {
            get
            {
                return (string)this.GetValue(ActiveRowControl.AppNameProperty);
            }
            set
            {
                this.SetValue(ActiveRowControl.AppNameProperty, value);
            }
        }

        private void lnkRow_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // TODO: Add event handler implementation here.
            ActiveIndex.lnkRow.Style = (Style)Resources["ActiveListRow"];
            lnkRow.Style = (Style)Resources["FocusedItemStyle"];
            ActiveIndex = this;
            string script = string.Format(@"UpdateAppDetails('{0}');", this.AppName);
            HtmlPage.Window.Eval(script);
            
            
            //HtmlPage.PopupWindow(new Uri("http://www.google.com"), "self", new HtmlPopupWindowOptions());
        }

        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            // TODO: Add event handler implementation here.
            Uri appUri;
            Uri.TryCreate(HtmlPage.Document.DocumentUri, "Application.aspx", out appUri);
            HtmlPage.Window.Navigate(appUri);
        }

        private void UserControl_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
        	// TODO: Add event handler implementation here.
            MessageBox.Show(sender.GetType().FullName);
        }



    }
}